#include <bits/stdc++.h>
// 2025/07/20
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

string s;
int dp[1000001];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> s;
    s = ' ' + s;
    int ans = 0, pos = 0;
    for (int i = 2; i <= s.size(); i++) {
        if (s[i] == '(' || s[i] == '[')
            continue;
        if (s[i] == ')' && s[i - dp[i - 1] - 1] == '(')
            dp[i] = dp[i - 1] + 2 + dp[i - dp[i - 1] - 2];
        else if (s[i] == ']' && s[i - dp[i - 1] - 1] == '[')
            dp[i] = dp[i - 1] + 2 + dp[i - dp[i - 1] - 2];
        if (dp[i] > ans)
            ans = dp[i], pos = i;
    }
    cout << s.substr(pos - ans + 1, ans);
    return 0;
}